const constans = require('../../constans/constans.js');
const request = require('../../request.js');
const Toast = require('../../utils/Toast.js');
const LogUtils = require('../../utils/LogUtils.js');
const util = require('../../utils/util.js')
const app = getApp();
Page({
  data: {
    height1:0,
    wode:'none',
  },
  onReady(){

  }, onLoad(options){

  


    console.log(options.a)
      if(options.a!=undefined){
        wx.navigateTo({
          url: '../../pages/packet/packet',
        })
      }
    let that = this;
    // 获取系统信息
    wx.getSystemInfo({
      success: function (res) {
        // 获取可使用窗口宽度
        let clientHeight = res.windowHeight;
        // 获取可使用窗口高度
        let clientWidth = res.windowWidth;
        // 算出比例
        let ratio = 750 / clientWidth;
        // 算出高度(单位rpx)
        let height = clientHeight * ratio;
        // 设置高度
        that.setData({
          height1: height
        });
      }
    });
   

  },onShow(){

  },scanCode: function () {
  
    
    var _this = this;
    Toast.loading("扫描中...");
    wx.scanCode({
      success: function (res) {
        LogUtils.log(res.path);
        
        wx.navigateTo({
          url: '../../' + res.path, 
        })
        var path = res.path;
      
      },
      fail: function () {
        Toast.error("扫描失败");
      },
      complete: function () {
        Toast.hideLoading();
      }
    })
  },
  toProblem:function(){
    wx.navigateTo({
      url: '../../pages/problem/problem',
    })

  },
  bindgetuserinfo: function (e) {
    // 判断是否已经注册
      Toast.loading("加载中...");
    wx.login({
      success: res => {
        console.log(res)
        request.get(
          constans.minlogin,
          { code: res.code },
          function (data) {
            console.log('下面');
            console.log(data)
            wx.setStorageSync('Authorization', data.header.Authorization);
            console.log(wx.getStorageSync('session'))
            console.log(e)
            if (data.data.data.user == null) {
            //  注册
            
              let that = this
              console.log(JSON.parse(e.detail.rawData))
              let user = JSON.parse(e.detail.rawData);
              console.log(user.nickName + user.avatarUrl + ';' + user.gender + ';' + user.city + ';' + user.country + ';' + user.province)
              let msg = e.detail.errMsg;

              if (msg === 'getUserInfo:ok') {

                console.log(app.requestHeader)
                request.post(
                  constans.register,
                  { iv: e.detail.iv, encryptedData: e.detail.encryptedData, nickName: user.nickName, avatarUrl: user.avatarUrl, gender: user.gender, city: user.city, country: user.country, province: user.province, session: wx.getStorageSync('session') },
                  function (data) {
                    console.log('注册');
                    console.log(data)
                    if (data.data.code == 0) {
                      Toast.hideLoading();
                      wx.navigateTo({
                        url: '../wode/wode'
                      })
                    } else {
                      
                      wx.showModal({
                        title: '提示',
                        showCancel: false,
                        content: data.data.message,
                      })

                    }
                  }
                )
              } else {


              }


            } else {
              Toast.hideLoading();
              wx.navigateTo({
                url: '../../pages/wode/wode',
              })
            }
          })
      }
    });

   

  }
  
  })